﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using CoreInmobiliario.Data;

namespace CoreInmobiliario.Business
{
    [DataObject]
    public class Servicios
    {
        public static Servicios GetInstance()
        {
            return new Servicios();
        }

        private static DBDataContext GetDBDataContext()
        {
            Factories.DBDataContextFactory factory = new Factories.DBDataContextFactory();
            return factory.CreateDataContext() as DBDataContext;
        }

        public Data.Servicio1 GetById(int serviciosId)
        {
            Data.Servicio1 servicios = null;

            using (DBDataContext dataContext = GetDBDataContext())
            {
                try
                {
                    servicios = dataContext.Servicio1s.FirstOrDefault(s => s.ServiciosId.Equals(serviciosId));
                }
                catch (Exception ex)
                {

                }
            }
            return servicios;
        }

        public Boolean UpdateServicios(Data.Servicio1 s)
        {
            using (DBDataContext dc = GetDBDataContext())
            {
                try
                {
                    Data.Servicio1 servicio = dc.Servicio1s.FirstOrDefault(serv => serv.ServiciosId.Equals(s.ServiciosId));
                    servicio.Descripcion = s.Descripcion;

                    dc.SubmitChanges();
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
    }
}
